<template>
  <div>
    <friend style="margin-bottom: 20px;" :indexCount="indexCount"></friend>
    <el-form :model="queryParams" class="frominfo" ref="queryForm" size="small" :inline="true" v-show="showSearch"
      label-width="68px">
      <div class="from-item">
        <el-form-item label="微信名称" prop="wcName">
          <el-input v-model="queryParams.wcName" @keyup.enter.native="handleQuery" placeholder="好友微信名称" clearable />
        </el-form-item>
        <el-form-item label="微信备注" prop="wcRemark">
          <el-input v-model="queryParams.wcRemark" @keyup.enter.native="handleQuery" placeholder="请输入好友微信备注" clearable />
        </el-form-item>
        <el-form-item label="发布时间" prop="beginTime">
          <el-date-picker v-model="chatTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
            range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>

        <el-form-item label="好友标签" prop="wxLabel">
          <el-select v-model="queryParams.wcLabel" placeholder="请选择" clearable>
            <el-option v-for="dict, index in lable" :key="index" :label="dict" :value="dict" />
          </el-select>
        </el-form-item>
      </div>
      <div class="from-Btn">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" style="background-color: #0078fb;color: #fff;border-color: #0078fb;" size="mini"
          @click="handleUpdate"><svg-icon icon-class="aixin"
            style="margin-right: 10px;" />一键点赞</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="wcMomentsList" @selection-change="handleSelectionChange" ref="multipleTable"
      :header-cell-style="{ background: '#fcfcfd', color: '#000' }" :border="false">
      <el-table-column type="selection" width="55" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="微信名称" prop="wcUserName" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="发布朋友圈时间" prop="releaseTime" align="center" :show-overflow-tooltip="true" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属营销助手" prop="assistName" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="标签" prop="lableNames" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-for="item,index in scope.row.lableNames" :key="index">
            <span v-if="index!=0">,</span>{{ item }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="微信号" prop="wcUserId" align="center" :show-overflow-tooltip="true" />

      <el-table-column align="center" width="120" class-name="small-padding fixed-width">
        <template slot="header">
          <span>朋友圈详情</span>
          <el-tooltip class="item" effect="dark" content="进入查看朋友圈详情" placement="top">
            <i class="el-icon-warning" style="color:#818e96;"></i>
          </el-tooltip>
        </template>
        <template slot-scope="{ row }">
            <span @click="golink(row.id,row.assistwcId,row.assistName,row.wcUserName,row.releaseTime,row.wcUserId,row.wcNoteName)" style="cursor: pointer;color:#0078fb">详情</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
    
<script>

import request from '@/utils/request'
import friend from '../components/friend.vue'
import mathNum from "../components/daily.js"
// import { number } from 'echarts';
export default {
  name: "WcGroupsInfo",
  dicts: ['sys_friendlabel_type'],
  components: {
    friend,
  },
  data() {
    return {
      indexCount: [{ name: '今日好友新增动态', num: 0, type: 1, bili: 0 }, { name: '未点赞动态', num: 0, type: 1, bili: 0 }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微信朋友圈信息表格数据
      wcMomentsList: [],
      // wcMomentsList: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      chatTime: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        wcName: null,
        wxRemark: null,
        beginTime: null,
        endTime: null,
        wcLabel: null,
        lableNames: null,
        wcUserId: null
      },
      lable: [],
    };
  },
  created(){
    this.getLable()
    this.getList()
    this.init()
  },
  mounted() {

  },
  methods: {
    golink(id,wcId,wcName,userName,rtime,userId,noteName){
      this.$router.push({ path:'/tuoke/friend_details',name:'friend_details',query:{id,wcId,wcName,userName,rtime,userId,noteName}}).catch(()=>{});
    },
    init(){
      this.indexCount=[{ name: '今日好友新增动态', num: 0, type: 1, bili: 0 }, { name: '未点赞动态', num: 0, type: 1, bili: 0 }]
      getChange({day:1}).then(res=>{
        //console.log(res)
        if(res.code==200){
          if(res.data){
             if(res.data.userChangesVOS!=null&&res.data.userChangesVOS!=''){
              this.indexCount[0].type=mathNum(res.data.userChangesVOS[0].dayAddFriend,res.data.userChangesVOS[0].ddayAddFriend).split('_')[0]
              this.indexCount[0].bili=mathNum(res.data.userChangesVOS[0].dayAddFriend,res.data.userChangesVOS[0].ddayAddFriend).split('_')[1]
              this.indexCount[0].num=res.data.userChangesVOS[0].dayAddFriend
              
              this.indexCount[1].type=mathNum(res.data.userChangesVOS[0].dayNotLike,res.data.userChangesVOS[0].ddayNotLike).split('_')[0]
              this.indexCount[1].bili=mathNum(res.data.userChangesVOS[0].dayNotLike,res.data.userChangesVOS[0].ddayNotLike).split('_')[1]
              this.indexCount[1].num=res.data.userChangesVOS[0].dayNotLike
             }
          }
        }
      })
    },
    getLable() {
      getLableInfo().then(res => {
        //console.log(res)
        if (res.code == 200) {
          this.lable = res.data.map(item => {
            return item.lableName
          })
        }
      })
    },
    /** 查询微信朋友圈信息列表 */
    getList() {
      this.loading = true;
      listWcMoments(this.queryParams).then(res => {
        //console.log(res)
        if (res['code'] == 200) {
          const dt = res['data'];
          this.total = dt['total'];
          this.wcMomentsList = dt['rows'];
        }
        this.loading = false;
      });
      setTimeout(()=>{
        this.loading = false;
      },2000)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wcUserId: null,
        likeState: null,
        releaseDetail: null,
        releaseTime: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        assistName: null,
        lableNames: null,
        wcUserId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.beginTime = null
      this.queryParams.endTime = null
      if (this.chatTime != '' && this.chatTime != null) {
        this.queryParams.beginTime = this.chatTime[0]+' 00:00:00'
        this.queryParams.endTime = this.chatTime[1]+' 23:59:59'
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.chatTime=[]
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        id: null,
        wcName: null,
        wxRemark: null,
        beginTime: null,
        endTime: null,
        wcLabel: null,
        lableNames: null,
        wcUserId: null
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => {
          return { id:item.id, wcid: item.assistwcId }
      })
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.selectedIds = selection.map(item => item.id);
    },
    handleUpdate() {
      if(this.ids) {
        updateWcMoments(this.ids).then((res) => {
          this.ids=[]
          this.$refs.multipleTable.clearSelection();
          this.$modal.msgSuccess("操作成功");
        });
      }
    },
    
  }
};

/** js请求 调用 */

// 查询微信朋友圈信息列表
export function listWcMoments(query) {
  return request({
    url: '/wcMoments/getRamlist',
    method: 'POST',
    params: query
  })
}
export function updateWcMoments(data) {
  return request({
    url: '/wcMoments/editRamonById',
    method: 'post',
    data: data // 直接将对象作为请求体发送
  })
}
// 获取微信标签信息
export function getLableInfo() {
  return request({
    url: '/wxassistant/wcuser_lable_copy/pagex',
    method: 'get',
  })
}
export function getChange(data) {
  return request({
    url: '/skmodulemoments/wcUserChanges/GetUserChangesListTb',
    method: 'get',
    params:data
  })
}

</script>
<style scoped lang="scss">
.frominfo {
  display: flex;
  background-color: #fff;
  padding: 10px;
  padding-bottom: 0;
  margin-bottom: 20px;

  .from-item {
    display: flex;
    flex-wrap: wrap;
  }

  .from-Btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 20%;
  }
}

.linebtn {
  display: flex;
  margin: -10px 0 10px 5px;
  height: 38px;

  .btn {
    width: 110px;
    text-align: center;
    line-height: 38px;
    font-size: 14px;
    color: #8c8c8c;
    margin-right: 10px;
    border: 1px solid #eaeff2;
    background-color: #fff;
    border-radius: 5px;

    .link-type {
      color: #8c8c8c;
    }
  }

  .select {
    background-color: #eaf6ff;
    border: 1px solid #288dfc;
    color: #288dfc;
    font-weight: 550;
  }
}
</style>